<template>
  <div>
    <el-input style="width: 70px" v-model="name"></el-input><el-button icon="el-icon-search" circle @click="paging(1)"></el-button>
    <el-button plain @click="toAdd">增加</el-button>
  <el-table :data="page.list">

    <el-table-column prop="a_id" label="序号" width="440"></el-table-column>
    <el-table-column prop="a_username" label="姓名" width="420"></el-table-column>

    <el-table-column label="操作" prop="a_id">

      <template slot-scope="scope">
        <el-button type="primary" icon="el-icon-edit" circle @click="toUpdate(scope.row.a_id)"></el-button>
        <el-button type="danger" icon="el-icon-delete" circle @click="del(scope.row.a_id)"></el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page.curPage" :page-sizes="[2,3,4,5]" :page-size="page.pageSize" layout="total,sizes,prev,pager,next,jumper" :total="page.count"></el-pagination>
  </div>
</template>

<script>

  export default {
    data() {
      return {
        pageSize:2,
        admin:{},
        page:{},
        name:'',
      }
    },
    methods:{
      paging(curPage){
        this.$axios.get('/AdminServlet/list?curPage='+curPage + '&a_username=' + this.name + '&pageSize=' + this.pageSize)
          .then(resp=>{
            this.page = resp.data;
          })
      },
      toAdd(){
        this.$router.push('/admin/add/')

      },
      toUpdate(id){
        this.$router.push('/admin/update/' + id)
      },
      del(id){
        this.$axios.get('AdminServlet/del?a_id='+ id)
          .then(resp=>{
            this.paging(1)
          })
      },
      handleCurrentChange(newPage){
        this.paging(newPage)
      },
      handleSizeChange(newSize){
        this.pageSize = newSize;
        this.paging(1)
      }
    },
    created() {
      this.admin = this.$store.state.admin;
      this.paging(1)
    },

  };
</script>

<style scoped>

</style>
